package com.leyou.user.web;

import com.leyou.user.dto.AddressDTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 付
 */
@RestController
@RequestMapping("address")
public class AddressController {
    @GetMapping("hello")
    public ResponseEntity<String> hello(){
        //登录校验
        return ResponseEntity.ok("上海市浦东新区航头镇航都路18号");
    }

    @GetMapping("me")
    public ResponseEntity<String> me(){
        //登录校验
        return ResponseEntity.ok("上海市浦东新区航头镇航都路19号");
    }

    @GetMapping("/{id}")
    public ResponseEntity<AddressDTO> queryAddressById(@PathVariable("id") Long id){
        //todo 去数据库根据id查询地址
        AddressDTO address = new AddressDTO();
        address.setId(1L);
        address.setUserId(30L);
        address.setStreet("航头镇航头路18号传智播客 3号楼");
        address.setCity("上海");
        address.setDistrict("浦东新区");
        address.setAddressee("虎哥");
        address.setPhone("15800000000");
        address.setProvince("上海");
        address.setPostcode("210000");
        address.setIsDefault(true);
        //校验查询到的地址是否属于当前用户
//        Long userid = UserHolder.getUser().getId();
//        if (!Objects.equals(address.getUserId(),userid)){
//          throw new LyException(403,"没有权限访问");
//        }

        return ResponseEntity.ok(address);
    }
}

